package com.cdtu.outtake.controller;

import com.cdtu.outtake.common.Result;
import com.cdtu.outtake.domain.OrderPo;
import com.cdtu.outtake.domain.OrderType;
import com.cdtu.outtake.dto.OrderDDto;
import com.cdtu.outtake.dto.OrderDto;
import com.cdtu.outtake.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : shl
 * @Date 2024/4/6 12:24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/order")
public class OrderController {
    private final IOrderService orderService;

    /**
     * 创建订单
     * @param order
     * @return
     */
    @PostMapping
    public Result<Object> createOrder(@RequestBody(required = false) OrderPo order) {
        orderService.createOrder(order);
        return Result.ok();
    }

    /**
     * 根据订单状态获取对应订单
     * @param type
     * @return
     */
    @GetMapping("/{type}")
    public Result<List<OrderDto>> getOrdersByStatus(@PathVariable("type") String type) {
        List<OrderDto> orders = orderService.getOrdersByType(OrderType.valueOf(type));
        return Result.ok(orders);
    }

    /**
     * 获取当前进行中的订单
     * @return
     */
    @GetMapping("/current")
    public Result<List<OrderDDto>> getCurrentOrder() {
        List<OrderDDto> currentOrder = orderService.getCurrentOrder();
        return Result.ok(currentOrder);
    }

    /*
    @GetMapping("/submit/{shopId}")
    public Result<Object> submitOrder(@PathVariable("shopId") Long shopId) {
        OrderDDto orderDDto = orderService.makeOrder(shopId);
        return Result.ok(orderDDto);
    }

*/
}
